import { BillApi } from '@/api/Bill.api.js'
import { SysWelfarePercentEmployeeCommercialConfigApi } from '@/api/SysWelfarePercentEmployeeCommercialConfig.api.js'
import { SysWelfarePercentNoCommercialConfigApi } from '@/api/SysWelfarePercentNoCommercialConfig.api.js'
// import { FormShangbaoFilter, FormShangbaoFilterItem } from './EBformData.js'
import { xinziThead } from './EBtableHead.js'
import DeleteEmployeeModal from './modal/deleteEmployeeModal.vue'
import _cloneDeep from 'clone-deep'
import { Common } from '@/utils/common.js'
import { EBbase } from './EBbase.js'

export default {
  props: {
    serviceFeeType: {
      type: Number,
      default: 0
    },
    isInsuranceInfoSet: {
      type: Boolean,
      default: false
    }
  },

  components: {
    DeleteEmployeeModal
  },

  data () {
    return {
      isOnlyView: true,
      canEditor: null,
      isCanSave: true,
      employeeId: '',
      isBatch: false,
      xinziThead: _cloneDeep(xinziThead),
      xinziTableData: [],
      tableComone: {
        pageIndex: 1, // 页码
        totalRows: 0, // 总条数
        pageSize: 10 // 当前页面展示条数
      },
      isEdit: false,
      isFromRoster: null
    }
  },

  mounted () {
    this.employeeId = this.$route.query.employeeId // 员工ID
    this.companyId = this.$route.query.companyId // 公司ID
    this.companyName = this.$route.query.companyName // 公司名称
    this.isFromRoster = this.$route.query.isFromRoster // 是否从员工管理页面过来
    this.canEditor = !!(this.$route.query.checkEmployeeNum || this.$route.query.isCreateNew || this.$route.query.isBatch)
    this.employeeBasicInfo = JSON.parse(localStorage.getItem('employeeBasicInfo')) // 当前员工基本信息
    this.isBatch = this.$route.query.isBatch // 是否批量

    // this.formShangbaoFilter.employeeGUID = this.$route.query.employeeId // 员工ID

    if (this.$route.query.isCreateNew) { // isCreateNew参数为true时，为新增
      this.isOnlyView = false
    }
  },

  methods: {
    // 上一步
    handlepageUp () {
      if ([3, 13, 23, 123].indexOf(this.serviceFeeType) !== -1) { // 参保种类选择了'商业保险' || '社保+商保' || '公积金+商保' || '社保+公积金+商保'
        Common.pageUp(this, 6)
      } else if ([2, 12].indexOf(this.serviceFeeType) !== -1) { // 参保种类选择了'公积金' || '社保+公积金'
        Common.pageUp(this, 5)
      } else if (this.serviceFeeType === 1) { // 参保种类选择了'社保'
        Common.pageUp(this, 4)
      } else {
        Common.pageUp(this)
      }
    },

    /**
     * 分页页码变动
     * @param {Number} val pageIndex
     */
    onChangePage (val) {
      this.tableComone.pageIndex = val
      this.query()
    },
    /**
     * 分页页码变动
     * @param {Number} val pageSize
     */
    onpageSizeChange (val) {
      this.tableComone.pageIndex = 1
      this.tableComone.pageSize = val
      this.query()
    },

    // 获取薪资记录
    async query (selectId) {
      var params = {
        EmployeeId: this.employeeId,
        HasPaging: true,
        PageIndex: this.tableComone.pageIndex,
        PageSize: this.tableComone.pageSize
      }
      let res = await BillApi.employeeSalaryDetails(params)
      console.log('获取薪资记录res: ', res)
      if (res.status === 200 && res.data.success) {
        this.xinziTableData = res.data.data
        this.tableComone.totalRows = res.data.totalRows
      }
    },

    // 返回员工花名册列表
    goEmployeeBookList () {
      EBbase.goEmployeeBookList(this.$router, this.companyId, this.companyName)
    },

    // 返回员工管理
    goRoster () {
      EBbase.goRoster(this.$router)
    }
  }
}
